package me.yuxiaoyao.example.lock.response;

/**
 * @author kerryzhang on 2020/12/23
 */

public class ApiResponse<T> {
    private final Integer status;
    private final String message;
    private final T data;
    private final String path;
    private final long timestamp;

    public ApiResponse(Builder<T> builder) {
        this.status = builder.status;
        this.message = builder.message;
        this.data = builder.data;
        this.path = builder.path;
        this.timestamp = builder.timestamp;
    }


    public Integer getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public String getPath() {
        return path;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public static <T> Builder<T> builder(Integer status) {
        return new Builder<T>();
    }

    public static <T> Builder<T> with(Integer status) {
        return new Builder<T>().setStatus(status);
    }

    public static final class Builder<T> {
        private Integer status;
        private String message;
        private T data;
        private String path;
        private long timestamp = System.currentTimeMillis();

        public Builder<T> setStatus(Integer status) {
            this.status = status;
            return this;
        }

        public Builder<T> setMessage(String message) {
            this.message = message;
            return this;
        }

        public Builder<T> setData(T data) {
            this.data = data;
            return this;
        }

        public Builder<T> setPath(String path) {
            this.path = path;
            return this;
        }

        public Builder<T> setTimestamp(long timestamp) {
            this.timestamp = timestamp;
            return this;
        }

        public ApiResponse<T> build() {
            return new ApiResponse<>(this);
        }
    }
}
